#include <nxos.h>

NX_PRIVATE void VFS_Test(void)
{
    NX_Printf("VFS test");
    NX_Error err;
    int fd = NX_FileOpen("/user_test", NX_FILE_RDONLY, 0);
    
    if (fd < 0)
    {
        NX_Printf("file open failed with %d\n", NX_ErrorGet());
        return;
    }

    char buf[32];
    NX_Size len = NX_FileRead(fd, buf, 32);
    err = NX_ErrorValue;
    NX_Printf("read %d with err %d\n", len, err);

    NX_FileSetPointer(fd, 0, NX_FILE_SEEK_END);

    len = NX_FileRead(fd, buf, 32);
    err = NX_ErrorValue;
    NX_Printf("read %d with err %d %s\n", len, err, NX_ErrorToString(err));

    NX_FileSetPointer(fd, 0, NX_FILE_SEEK_SET);
    err = NX_ErrorValue;
    len = NX_FileRead(fd, buf, 32);
    err = NX_ErrorValue;
    NX_Printf("read %d with err %d\n", len, err);

    NX_FileClose(fd);

    NX_Printf("file test ok!\n");
}

NX_Error TEST_Syscall(char *cmdline)
{
    char *s = "syscall test!\n";
    NX_DebugLog(s, sizeof(s));
    VFS_Test();
    return NX_EOK;
}
